<?php
class ActivityJumpVo extends SzAbstractMySqlVo
{

    private $userId;
    private $indexId;
    private $gameState;
    private $freeTime;
    private $videoTimes;
    private $freeRefreshTime;
    private $score;
    private $status;
    private $reward;

    /**
     * Initialize ActivityJumpVo.
     *
     * @param $userId
     * @param $indexId
     * @param $gameState
     * @param $freeTime
     * @param $videoTimes
     * @param $freeRefreshTime
     * @param $score
     * @param $status
     * @param $reward
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return ActivityJumpVo
     */
    public function __construct($userId, $indexId, $gameState, $freeTime, $videoTimes, $freeRefreshTime, $score, $status, $reward, $isInsert = false) {
        $this->userId = $userId;
        $this->indexId = $indexId;
        $this->gameState = $gameState;
        $this->freeTime = $freeTime;
        $this->videoTimes = $videoTimes;
        $this->freeRefreshTime = $freeRefreshTime;
        $this->score = $score;
        $this->status = $status;
        $this->reward = json_decode($reward, true);

        $this->isInsert = $isInsert;
        $this->voClassName = 'ActivityJumpVo';
        $this->ormName = 'ActivityJump';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'indexId' => $this->getIndexId(),
            'gameState' => $this->getGameState(),
            'freeTime' => $this->getFreeTime(),
            'videoTimes' => $this->getVideoTimes(),
            'freeRefreshTime' => $this->getFreeRefreshTime(),
            'score' => $this->getScore(),
            'status' => $this->getStatus(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'indexId' => $this->getIndexId(),
            'gameState' => $this->getGameState(),
            'freeTime' => $this->getFreeTime(),
            'videoTimes' => $this->getVideoTimes(),
            'freeRefreshTime' => $this->getFreeRefreshTime(),
            'score' => $this->getScore(),
            'status' => $this->getStatus(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getIndexId(),
            $this->getGameState(),
            $this->getFreeTime(),
            $this->getVideoTimes(),
            $this->getFreeRefreshTime(),
            $this->getScore(),
            $this->getStatus(),
            $this->getReward(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getIndexId()
    {
        return $this->indexId;
    }

    public function setIndexId($val)
    {
        $this->saveColumnStatus(1, $this->indexId);
        $this->indexId = $val;
    }

    public function getGameState()
    {
        return $this->gameState;
    }

    public function setGameState($val)
    {
        $this->saveColumnStatus(2, $this->gameState);
        $this->gameState = $val;
    }

    public function getFreeTime()
    {
        return $this->freeTime;
    }

    public function setFreeTime($val)
    {
        $this->saveColumnStatus(3, $this->freeTime);
        $this->freeTime = $val;
    }

    public function getVideoTimes()
    {
        return $this->videoTimes;
    }

    public function setVideoTimes($val)
    {
        $this->saveColumnStatus(4, $this->videoTimes);
        $this->videoTimes = $val;
    }

    public function getFreeRefreshTime()
    {
        return $this->freeRefreshTime;
    }

    public function setFreeRefreshTime($val)
    {
        $this->saveColumnStatus(5, $this->freeRefreshTime);
        $this->freeRefreshTime = $val;
    }

    public function getScore()
    {
        return $this->score;
    }

    public function setScore($val)
    {
        $this->saveColumnStatus(6, $this->score);
        $this->score = $val;
    }

    public function getStatus()
    {
        return $this->status;
    }

    public function setStatus($val)
    {
        $this->saveColumnStatus(7, $this->status);
        $this->status = $val;
    }

    public function getReward()
    {
        return json_encode($this->reward);
    }

    public function getRawReward()
    {
        return $this->reward;
    }

    public function setReward($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 12800) {
            SzLogger::get()->error('[ActivityJumpVo] The length of column reward exceed the limit, length / limit: ' . $encodedLength . ' / 12800');
            throw new SzException(10522, array('ActivityJumpVo', '12800', $encodedLength));
        } else if ($encodedLength > 11520) {
            SzLogger::get()->warn('[ActivityJumpVo] The length of column reward exceed the warning level, length / limit: ' . $encodedLength . ' / 12800');
        }
        $this->saveColumnStatus(8, $this->reward);
        $this->reward = $val;
    }

    public function updateFreeTime($val)
    {
        $this->saveColumnStatus(3, $this->freeTime);
        $this->freeTime -= $val;
        $this->freeTime = max($this->freeTime,0);
    }

}